home *** CD-ROM | disk | FTP | other *** search
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import org.gjt.sp.jedit.EBComponent;
- import org.gjt.sp.jedit.EBMessage;
- import org.gjt.sp.jedit.EditBus;
- import org.gjt.sp.jedit.GUIUtilities;
- import org.gjt.sp.jedit.MiscUtilities;
- import org.gjt.sp.jedit.View;
- import org.gjt.sp.jedit.jEdit;
- import org.gjt.sp.jedit.gui.DefaultFocusComponent;
- import org.gjt.sp.jedit.msg.PropertiesChanged;
- import org.gjt.sp.util.Log;
-
- public class QuickNotepad extends JPanel implements EBComponent, QuickNotepadActions, DefaultFocusComponent {
- private String filename;
- private String defaultFilename;
- private View view;
- private boolean floating;
- private QuickNotepadTextArea textArea;
- private QuickNotepadToolPanel toolPanel;
- // $FF: synthetic field
- static Class class$QuickNotepad;
-
- public QuickNotepad(View var1, String var2) {
- super(new BorderLayout());
- this.view = var1;
- this.floating = var2.equals("floating");
- if (jEdit.getSettingsDirectory() != null) {
- this.filename = jEdit.getProperty("options.quicknotepad.filepath");
- if (this.filename == null || this.filename.length() == 0) {
- this.filename = new String(jEdit.getSettingsDirectory() + File.separator + "qn.txt");
- jEdit.setProperty("options.quicknotepad.filepath", this.filename);
- }
-
- this.defaultFilename = this.filename;
- }
-
- this.toolPanel = new QuickNotepadToolPanel(this);
- this.add("North", this.toolPanel);
- if (this.floating) {
- this.setPreferredSize(new Dimension(500, 250));
- }
-
- this.textArea = new QuickNotepadTextArea();
- this.textArea.setFont(QuickNotepadOptionPane.makeFont());
- this.textArea.addKeyListener(new QuickNotepad$KeyHandler(this, (QuickNotepad$1)null));
- JScrollPane var3 = new JScrollPane(this.textArea);
- this.add("Center", var3);
- this.readFile();
- }
-
- public void focusOnDefaultComponent() {
- this.textArea.requestFocus();
- }
-
- public String getFilename() {
- return this.filename;
- }
-
- public void handleMessage(EBMessage var1) {
- if (var1 instanceof PropertiesChanged) {
- this.propertiesChanged();
- }
-
- }
-
- private void propertiesChanged() {
- String var1 = jEdit.getProperty("options.quicknotepad.filepath");
- if (!MiscUtilities.objectsEqual(this.defaultFilename, var1)) {
- this.saveFile();
- this.toolPanel.propertiesChanged();
- this.defaultFilename = var1;
- this.filename = this.defaultFilename;
- this.readFile();
- }
-
- Font var2 = QuickNotepadOptionPane.makeFont();
- if (!var2.equals(this.textArea.getFont())) {
- this.textArea.setFont(var2);
- }
-
- }
-
- public void addNotify() {
- super.addNotify();
- EditBus.addToBus(this);
- }
-
- public void removeNotify() {
- this.saveFile();
- super.removeNotify();
- EditBus.removeFromBus(this);
- }
-
- public void saveFile() {
- if (this.filename != null && this.filename.length() != 0) {
- try {
- FileWriter var1 = new FileWriter(this.filename);
- var1.write(this.textArea.getText());
- var1.close();
- } catch (IOException var2) {
- Log.log(9, class$QuickNotepad == null ? (class$QuickNotepad = class$("QuickNotepad")) : class$QuickNotepad, "Could not write notepad text to " + this.filename);
- }
-
- }
- }
-
- public void chooseFile() {
- String[] var1 = GUIUtilities.showVFSFileDialog(this.view, (String)null, 0, false);
- if (var1 != null && !var1[0].equals(this.filename)) {
- this.saveFile();
- this.filename = var1[0];
- this.toolPanel.propertiesChanged();
- this.readFile();
- }
-
- }
-
- public void copyToBuffer() {
- jEdit.newFile(this.view);
- this.view.getEditPane().getTextArea().setText(this.textArea.getText());
- }
-
- private void readFile() {
- if (this.filename != null && this.filename.length() != 0) {
- Object var1 = null;
-
- try {
- BufferedReader var6 = new BufferedReader(new FileReader(this.filename));
- StringBuffer var2 = new StringBuffer(2048);
-
- String var3;
- while((var3 = var6.readLine()) != null) {
- var2.append(var3).append('\n');
- }
-
- var6.close();
- this.textArea.setText(var2.toString());
- } catch (FileNotFoundException var4) {
- Log.log(9, class$QuickNotepad == null ? (class$QuickNotepad = class$("QuickNotepad")) : class$QuickNotepad, "notepad file " + this.filename + " does not exist");
- } catch (IOException var5) {
- Log.log(9, class$QuickNotepad == null ? (class$QuickNotepad = class$("QuickNotepad")) : class$QuickNotepad, "could not read notepad file " + this.filename);
- }
-
- }
- }
-
- // $FF: synthetic method
- static Class class$(String var0) {
- try {
- return Class.forName(var0);
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(var2.getMessage());
- }
- }
-
- // $FF: synthetic method
- static boolean access$100(QuickNotepad var0) {
- return var0.floating;
- }
-
- // $FF: synthetic method
- static View access$200(QuickNotepad var0) {
- return var0.view;
- }
- }
-